//package com.wjm.blog.core.filter;
//
//import com.alibaba.fastjson.JSONObject;
//import com.wjm.blog.common.enums.CommonEnum;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.stereotype.Component;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.util.Iterator;
//import java.util.Map;
//import java.util.Set;
//
//
///**
// * @author SHOWMAKER
// * @version 1.0
// * @date 2021/6/30 11:42
// */
//
//@Component
//@Slf4j
//public class TokenInterceptor implements HandlerInterceptor {
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//
//        //跨域请求会首先发一个option请求，直接返回正常状态并通过拦截器
//        if (request.getMethod().equals("OPTIONS")) {
//            response.setStatus(HttpServletResponse.SC_OK);
//            return true;
//        }
//        String url = request.getRequestURI();
//        log.info("RequestURI:" + url);
//        response.setCharacterEncoding("utf-8");
//        response.setContentType("application/json; charset=utf-8");
//
//        String token = request.getHeader(CommonEnum.Request.TOKEN);
//        log.info("token:{}", token);
//
//        //无需拦截
////        if (url.contains("remote")
////                || url.contains("wcsTaskPallet")
////                || url.contains("wmsBatchCancel")
////                || url.contains("batchConfirm")
////                || url.contains("updateTaskState")
////                || url.contains("selectByPalletCode")
////                || url.contains("batchSave")
////                || url.contains("getTaskStatus")
////                || url.contains("inrepo")
////                || url.contains("outrepo")
////                || url.contains("listInfoWmsByCode")
////                || url.contains("wmsStorageSpaces")
////                || url.contains("wmsOrgSpaces")
////                || url.contains("apiInter")
////                || url.contains("getFreePallets")
////                || url.contains("getFreeStorageSpaces")
////                || url.contains("wmsPalletsInfos")
////                || url.contains("wmsContactOrgs")
////                || url.contains("wmsStorageSpacess")) {
////            return true;
////        }
//
//
//        Boolean verify = TokenUtils.verify(token);
//
//        if (!verify) {
//            JSONObject json = new JSONObject();
//            json.put("message", "身份验证失败，请重新登录");
//            json.put("code", "9527");
//            response.getWriter().append(json.toString());
//            log.info("认证失败，未通过拦截器");
//        }
//
////        Map<String, String[]> parameterMap = request.getParameterMap();
////        paramsCheck(parameterMap);
//
//        return verify;
//    }
//
//    private void paramsCheck(Map<String, String[]> parameterMap) {
//        Set<String> set = parameterMap.keySet();
//        Iterator<String> it = set.iterator();
//        while (it.hasNext()) {
//            String key = (String) it.next();
//            String[] values = parameterMap.get(key);
//            values[0] = values[0].trim();
//            parameterMap.put(key, values);
//        }
//    }
//
//}
//
